package http

import (
	"context"
	"fmt"
	"go-api/internal/config"
	"go-api/router"
	"net/http"
	"time"
)

var httpServer *http.Server

func Serve() error {
	httpServer = &http.Server{
		Addr:              fmt.Sprintf(":%d", config.GetConfig().Server.Port),
		Handler:           router.InitRouter(),
		ReadTimeout:       5 * time.Second,
		ReadHeaderTimeout: 10 * time.Second,
	}

	return httpServer.ListenAndServe()
}

func Stop(ctx context.Context) error {
	fmt.Println("shutdown")
	return httpServer.Shutdown(ctx)
}
